package com.aatrox.bhsypro.controller;


import com.aatrox.bhsypro.entity.BUser;
import com.aatrox.bhsypro.entity.UAttention;
import com.aatrox.bhsypro.service.UAttentionService;
import com.aatrox.bhsypro.util.CookieUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class UAttentionController {
    @Autowired
    UAttentionService uAttentionService;
    @Autowired
    RedisTemplate<String,Object> redisTemplate;
    @ResponseBody
    @RequestMapping("/attention/{vid}")
    public String cha(@PathVariable("vid") int vid, HttpServletRequest request,HttpSession session){
        String ticket = CookieUtil.getCookieValue(request,"userTicket");
        BUser user = (BUser) redisTemplate.opsForValue().get("user:"+ticket+"uid:"+(session.getAttribute("buserId")));
        UAttention b=new UAttention(vid,user.getUid());
        uAttentionService.insertmes(b);
        System.out.println(vid+"qwqwqwqw");
        System.out.println(user.getUid()+"qwqwqwqw");
        return "成功了";
    }
}
